<?php
/**
 * Celebrio Kernel
 *
 * @copyright  Copyright (c) 2012 Celebio Software, s.r.o.
 * @package    Kernel
 */
namespace KernelModule\LogsModule\PerformanceModule;

use Nette\Object;

use KernelModule\LogsModule\PerformanceModule\IPerformanceLogs;

use Celebrio\WindowsAzure\AzureStorage\AzureStorageTable;
use Celebrio\Core\Config;

/**
 * Azure performance logs in Celebrio
 * 
 * @author Martin Novák
 */
class PerformanceLogsAzure extends Object implements IPerformanceLogs {
    
	/**
	 * returns array with stored statistics
	 * @return array statistics in two dimensions ([])(["count"],["average"])
	 */
    public function getBlocksList()
    {
    	$results = array();
    	$configArray = Config::current()->loadConfigArray("ProcessedTimers");

    	if($configArray && AzureStorageTable::connection()->tableExists($configArray["tablename"])) {
	    	$requests = AzureStorageTable::connection()->retrieveEntities($configArray["tablename"]);
	    	$results = array();
	    	foreach($requests as $request){
	    		$results[rawurldecode($request->getRowKey())] = array(
	    				"count" => $request->count,
	    				"average" => $request->average);
	    	}
    	}
    	return $results;
    }

}